import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,AlertController,ToastController} from 'ionic-angular';
import {SportDynamicService} from "../../providers/SportDynamicService";
import {UserInfo} from "../../model/UserInfo";
import {StorageService} from "../../providers/StorageService";
import {SPORT_DYNAMIC_IMG_PATH,USERFACE_PATH} from "../../providers/Constants";
import {BaseUI} from "../../common/baseui";

@IonicPage()
@Component({
  selector: 'page-my-sport-dynamic',
  templateUrl: 'my-sport-dynamic.html',
})
export class MySportDynamicPage extends BaseUI{

  sportDynamicList:any;
  userFacePath:string;
  sportDynamicImgPath:string;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public sportDynamicService:SportDynamicService,
              public storageService:StorageService,
              public alertCtrl:AlertController,
              public  toastCtrt:ToastController) {
      super();
      this.userFacePath =USERFACE_PATH;
      this.sportDynamicImgPath = SPORT_DYNAMIC_IMG_PATH;
  }

  ionViewDidLoad() {
    this.getSportDynamicList();
  }

  getSportDynamicList(){
    var userId =this.storageService.read<UserInfo>('UserInfo').id;
    this.sportDynamicService.selectMySportDynamic(userId).subscribe(res=>{
      this.sportDynamicList= res['data'];
    })
  }
  deleteSportDynamic(id){
    let confirm = this.alertCtrl.create({
      message: '是否确认删除此条动态？',
      buttons: [
        {
          text: '否',
          handler: () => {
          }
        },
        {
          text: '是',
          handler: () => {
            this.sportDynamicService.deleteSportDynamic(id).subscribe(res=>{
              super.showToast(this.toastCtrt,res['msg'],'bottom');
              if(res['status']==0){
                this.getSportDynamicList();
              }
            })
          }
        }
      ]
    });
    confirm.present();
  }

  //打开发布动态页面
  openPubSportDynamic(){
    this.navCtrl.push('PubSportDynamicPage');
  }
}
